/*
 * $Id: $
 */
package org.rcgwt.client.ui.grid.internal;

import org.rcgwt.client.ui.grid.internal.model.IViewModel;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class ViewModelDelta extends DefaultModelElementDelta<IViewModel> {

    private static final int SCROLL_POSITIONS_CHANGED = 0x0010;

    private int oldScrollLeft;

    private int newScrollLeft;

    private int oldScrollTop;

    private int newScrollTop;

    protected ViewModelDelta(IViewModel viewModel) {
        super(viewModel);
    }

    public void performScrollPositionsChanged(int oldScrollLeft,
            int oldScrollTop, int newScrollLeft, int newScrollTop) {

        if (hasContentChanged() == false) {
            updateKind(SCROLL_POSITIONS_CHANGED);

            this.oldScrollLeft = oldScrollLeft;
            this.oldScrollTop = oldScrollTop;
        }

        this.newScrollLeft = newScrollLeft;
        this.newScrollTop = newScrollTop;
    }

    public boolean hasScrollPositionsChanged() {
        return (getKind() & SCROLL_POSITIONS_CHANGED) > 0;
    }

    public int getOldScrollLeft() {
        return oldScrollLeft;
    }

    public int getNewScrollLeft() {
        return newScrollLeft;
    }

    public int getOldScrollTop() {
        return oldScrollTop;
    }

    public int getNewScrollTop() {
        return newScrollTop;
    }

    @Override
    protected String toValuesString() {
        return super.toValuesString() + " oldScroll=" + oldScrollLeft + "/"
                + oldScrollTop + " newScroll=" + newScrollLeft + "/"
                + newScrollTop;
    }

}
